package com.chang.soul.controller;

import com.chang.soul.conf.JwtIgnore;
import com.chang.soul.service.ArticleService;
import com.chang.soul.service.PaperService;
import com.chang.soul.service.ScaleService;
import com.chang.soul.service.UserService;
import com.chang.soul.util.Result;
import com.chang.soul.util.ResultUtil;
import com.alibaba.fastjson.JSONObject;
import com.sun.tools.javah.Gen;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 仪表盘接口
 */

@RestController
@RequestMapping("/dash")
@Api("仪表盘接口")
public class DashController {

    @Autowired
    PaperService paperService;
    @Autowired
    ArticleService articleService;
    @Autowired
    UserService userService;
    @Autowired
    ScaleService scaleService;
    /**
     * 获取文章数量、试题数量、量表数量、试题历史数量
     */
    @ApiOperation(value = "获取数据接口", notes = "无需Token", httpMethod = "GET")
    @GetMapping("/getDatas")
    @JwtIgnore
    public Result getDatas(){
        List<Integer> datas=new ArrayList<>();

        int articleCount=articleService.getArticleCount(); //文章数量
        int paperCount=paperService.getPaperCount();  //试题数量
        int scaleCount = scaleService.getScaleCounts(); //量表数量

        JSONObject jsonObject=new JSONObject();
        jsonObject.put("articleCount",articleCount);
        jsonObject.put("paperCount",paperCount);
        jsonObject.put("scaleCount",scaleCount);
        return ResultUtil.success(jsonObject);
    }

    /**
     * 获取性别数量，实现可视化饼图
     */
    @ApiOperation(value = "获取性别分布", notes = "无需Token", httpMethod = "GET")
    @GetMapping("/getGenderInfo")
    @JwtIgnore
    public Result getGenderInfo(){
        int manCount=0;
        int womanCount=0;
        int secretCount=0;

        manCount=userService.getCountByGender(1);
        womanCount=userService.getCountByGender(2);
        secretCount=userService.getCountByGender(0);

        System.out.println(womanCount);
        List<Integer> GenderNum=new ArrayList<>();
        List<String> Gender=new ArrayList<>();
        List<Double> list=new ArrayList<>();
        Gender.add("男生");
        Gender.add("女生");
        Gender.add("保密");

        GenderNum.add(manCount);
        GenderNum.add(womanCount);
        GenderNum.add(secretCount);

        double count=manCount+womanCount+secretCount;
        list.add(manCount/count);
        list.add(womanCount/count);
        list.add(secretCount/count);

        JSONObject jsonObject=new JSONObject();

        jsonObject.put("GenderNum",GenderNum);
        jsonObject.put("Gender",Gender);
        jsonObject.put("list",list);
        return ResultUtil.success(jsonObject);
    }
}
